package com.example.wjh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.wjh.entity.Announcement;
import com.example.wjh.entity.News;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;


@Mapper
public interface AnnouncementMapper extends BaseMapper<Announcement> {

    // 查询最新的三条资讯名称
    @Select("SELECT title FROM announcement ORDER BY id DESC LIMIT 3")
    List<Announcement> findLatestAnnouncements();

    @Select("<script> " +
            "SELECT * FROM announcement " +
            "<where> " +
            "<if test='title != null'> AND title LIKE CONCAT('%', #{title}, '%')</if> " +
            "<if test='publishtime != null'> AND publishtime LIKE CONCAT('%', #{publishtime}, '%')</if> " +
            "<if test='content != null'> AND content LIKE CONCAT('%', #{content}, '%')</if> " +
            "</where> " +
            "</script>")
    List<Announcement> searchAnnouncement(
            @Param("title") String title,
            @Param("publishtime") String publishtime,
            @Param("content") String content);
}
